package com.hx.vending.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hx.vending.bean.CapitalFlow;
import com.hx.vending.dao.CapitalFlowMapper;
import com.hx.vending.service.ICapitalFlowService;
import com.hx.vending.util.Msg;
import com.hx.vending.util.ToolUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator |on 2018/11/28.
 * 流水
 */
@Service
public class CapitalFlowServiceImpl implements ICapitalFlowService{


    @Autowired
    private CapitalFlowMapper capitalFlowMapper;


    /**
     * 查询余额明细 0微信 1支付宝
     * @param userId
     * @param startTime
     * @param stopTime
     * @param pageNum
     * @param pageSize
     * @return
     */
    public Msg selectCapitalFlowByTime(Integer userId,Integer type, String startTime, String stopTime, Integer pageNum, Integer pageSize) {

        if (ToolUtil.isNotEmpty(userId)) {
            if (ToolUtil.isEmpty(startTime)) {
                startTime = null;
            }
            if (ToolUtil.isEmpty(stopTime)) {
                stopTime = null;
            }
            PageHelper.startPage(pageNum, pageSize);//1,10
            List<CapitalFlow> capitalFlowList = new ArrayList<>();
            List<Integer> integerList = new ArrayList<>();
            if(type == 0){
                integerList.add(2);
                integerList.add(4);
                integerList.add(6);
                capitalFlowList = capitalFlowMapper.selectByWxPay(userId,startTime,stopTime,integerList);

            }else if(type == 1){
                integerList.add(1);
                integerList.add(3);
                integerList.add(5);
                capitalFlowList = this.capitalFlowMapper.selectByTime(userId, startTime, stopTime,integerList);

            }
            PageInfo page = new PageInfo(capitalFlowList, 5);
            return Msg.success().add("pageInfo", page);
        }else {
            return Msg.fail();
        }
    }

}
